using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Axe.Data.Mapping.Attributes
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class MappedFieldAttribute : Attribute
    {
        public string FieldName { get; set; }

        public MappedFieldAttribute()
        {

        }

        public MappedFieldAttribute(string fieldName)
        {
            FieldName = fieldName;
        }

        public bool IsNullable { get; set; }
        public bool IsPK { get; set; }

        public bool IsUniquie { get; set; }
        public bool IsIndexed { get; set; }

        public bool IsCalculated { get; set; }

        public Type ConverterType { get; set; }
        public Type TargetType { get; set; }

        #region internal bool UseOnInsert
        internal bool UseOnInsert
        {
            get
            {
                if (IsCalculated)
                    return false;
                return true;
            }
        } 
        #endregion

        #region internal bool UseOnUpdate
        internal bool UseOnUpdate
        {
            get
            {
                if (IsCalculated)
                    return false;

                return true;
            }
        } 
        #endregion
    }

    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public class InnerMappedFieldAttribute : MappedFieldAttribute
    {
        public string InnerPropertyName { get; protected set; }

        public InnerMappedFieldAttribute(string innerPropertyName, string fieldName)
            : base(fieldName)
        {
            if (String.IsNullOrEmpty(fieldName))
                throw new ArgumentNullException("fieldName", "Field name must be specified for InnerMappedField Attribute.");

            if (String.IsNullOrEmpty(innerPropertyName))
                throw new ArgumentNullException("innerPropertyName", "Inner property cannot be null or empty");

            InnerPropertyName = innerPropertyName;
        }

        
    }
}
